//
//  BtnViewController.m
//  test02
//
//  Created by lzh on 2021/3/6.
//  Copyright © 2021 NO. All rights reserved.
//

#import "BtnViewController.h"
#import <Masonry.h>
@interface BtnViewController ()

@end

@implementation BtnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"xuanze"] forState:UIControlStateNormal];
    [btn setTitle:@"关注" forState:UIControlStateNormal];
    btn.backgroundColor= [UIColor blueColor];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(100);
        make.top.equalTo(self.view).offset(100);
        make.height.mas_offset(50);
    }];
    [btn layoutIfNeeded];
//    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
    NSLog(@"%@--%@",NSStringFromCGSize(btn.intrinsicContentSize),NSStringFromCGSize(btn.titleLabel.bounds.size));
    [self topImage:btn];
}

-(void)rightImage:(UIButton *)btn{
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, btn.titleLabel.bounds.size.width, 0, -btn.titleLabel.bounds.size.width);
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, -btn.imageView.bounds.size.width, 0,btn.imageView.bounds.size.width);
}
-(void)topImage:(UIButton *)btn{
    btn.imageEdgeInsets = UIEdgeInsetsMake(-btn.titleLabel.bounds.size.height/2.0, (btn.bounds.size.width-btn.imageView.bounds.size.width)/2.0, btn.titleLabel.bounds.size.height/2.0, (btn.bounds.size.width-btn.imageView.bounds.size.width)/2.0);
    btn.titleEdgeInsets = UIEdgeInsetsMake(btn.imageView.bounds.size.height/2.0, -(btn.bounds.size.width-btn.titleLabel.bounds.size.width)/2.0, -btn.imageView.bounds.size.height/2.0,(btn.bounds.size.width-btn.titleLabel.bounds.size.width)/2.0);
}



@end
